package dataStructs.tree;

import lombok.Data;

/**
 * @author Jonny Long
 * @date 2021/3/10 18:51
 */
@Data
public class AVLTree {
    private AVLNode root;

    // 获取树的高度
    public int height(AVLNode tree) {
        if (tree != null) {
            return tree.getHeight();
        }
        return 0;
    }

    // 比较两个值的大小
    public int max(int a, int b) {
        return Math.max(a, b);
    }

    // LL的旋转代码
    public AVLNode leftLeftRotation(AVLNode k2) {
        AVLNode k1;
        k1 = k2.getLeft();
        k2.setLeft(k1.getRight());
        k1.setRight(k2);
        int k2Height = max(height(k2.getLeft()), height(k2.getRight())) + 1;
        k2.setHeight(k2Height);
        int k1Height = max(height(k1.getLeft()), k2.getHeight()) + 1;
        k1.setHeight(k1Height);
        return k1;
    }


}
